home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
Pascal
/
SWar
/
Debris.p
next >
Wrap
Text File
|
1995-06-15
|
3KB
|
105 lines
unit Debris;
interface
uses
{$IFC UNDEFINED THINK_PASCAL}
Types, QuickDraw, Events, Menus, Dialogs, Fonts, Resources, Devices,
{$ENDC}
Globals, Util;
procedure InitDebris;
procedure CreateDebris (number, tics, h, v, hv, vv: Integer);
procedure MoveDebris;
procedure DrawDebris;
implementation
procedure InitDebris;
{evar DEBRISREC gDebrisRecs[MAX_DEBRIS], gOldDebrisRecs[MAX_DEBRIS]:xtern;}
var
i: Integer;
begin
for i := 0 to MAX_DEBRIS - 1 do
begin
gDebrisRecs[i].where.v := -1;
gDebrisRecs[i].where.h := -1;
gDebrisRecs[i].vel.v := -1;
gDebrisRecs[i].vel.h := -1;
gDebrisRecs[i].countdown := 0;
end; (* for *)
end; (* InitDebris() *)
procedure CreateDebris (number, tics, h, v, hv, vv: Integer);
var
i: Integer;
begin
for i := 0 to MAX_DEBRIS - 1 do
if (gDebrisRecs[i].countdown = 0) then
begin
gDebrisRecs[i].where.v := v + RngRnd(-3, 3);
gDebrisRecs[i].where.h := h + RngRnd(-3, 3);
gDebrisRecs[i].vel.v := vv + RngRnd(-3, 3);
gDebrisRecs[i].vel.h := hv + RngRnd(-3, 3);
gDebrisRecs[i].countdown := tics;
gDebrisRecs[i].color.red := RngRnd(0, 256) * 256;
gDebrisRecs[i].color.green := RngRnd(0, 256) * 256;
gDebrisRecs[i].color.blue := RngRnd(0, 256) * 256;
number := number - 1;
if number = 0 then
exit(CreateDebris);
end; (* if *)
end; (* CreateDebris() *)
procedure MoveDebris;
var
i: Integer;
begin
for i := 0 to MAX_DEBRIS - 1 do
if gDebrisRecs[i].countdown <> 0 then
begin
gDebrisRecs[i].countdown := gDebrisRecs[i].countdown - 1;
gDebrisRecs[i].where.h := gDebrisRecs[i].where.h + gDebrisRecs[i].vel.h;
gDebrisRecs[i].where.v := gDebrisRecs[i].where.v + gDebrisRecs[i].vel.v;
if (gDebrisRecs[i].where.v < 0) then
gDebrisRecs[i].vel.v := -gDebrisRecs[i].vel.v;
if (gDebrisRecs[i].where.v > 479) then
gDebrisRecs[i].vel.v := -gDebrisRecs[i].vel.v;
if (gDebrisRecs[i].where.h < 0) then
gDebrisRecs[i].vel.h := -gDebrisRecs[i].vel.h;
if (gDebrisRecs[i].where.h > 639) then
gDebrisRecs[i].vel.h := -gDebrisRecs[i].vel.h;
end; (* if *)
end; (* MoveDebris() *)
procedure DrawDebris;
var
hloc: Integer;
i: Integer;
savePort: GrafPtr;
{ extern gXv:Integer;}
{ eCGrafPort *gOSPtr:xtern;}
{ eRGBColor myBlack:xtern; }
begin
GetPort(savePort);
SetPort(GrafPtr(gOSPtr));
for i := 0 to MAX_DEBRIS - 1 do
begin
if gOldDebrisRecs[i].countdown <> 0 then
SetCPixel(gOldDebrisRecs[i].where.h, gOldDebrisRecs[i].where.v, myBlack);
if gDebrisRecs[i].countdown <> 0 then
SetCPixel(gDebrisRecs[i].where.h, gDebrisRecs[i].where.v, gDebrisRecs[i].color);
gOldDebrisRecs[i] := gDebrisRecs[i];
end; (* for *)
SetPort(savePort);
end; (* DrawDebris() *)
end.